<?php
//DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
if ($_SESSION['logged_in'] == 0) {
	require ('../../admin/security_check.php');
} else {
	if ($_POST)
{
	processTable('groups');
}	
/* GROUPS group query main query for page*/
$group_sql = "SELECT meetings.group_id, groups.id as id, groups.groupname AS groupname, groups.ir_fname AS ir_fname, groups.ir_lname AS ir_lname, count(meetings.group_id) AS counter
	FROM meetings
	RIGHT JOIN groups ON groups.id = meetings.group_id
	GROUP BY meetings.group_id, groups.groupname
	ORDER BY groupname ASC";
$group_result = mysql_query($group_sql) or die(mysql_error());
$num_rows = mysql_num_rows($group_result);	
?>
<script language="javascript" type="text/javascript">
var table = 'groups';

$(document).ready(function(){ 
	$('.meetingEdit').editable('inlineEdit.php', {
			 indicator : 'Saving...',
			 tooltip   : 'Click to edit...',
			 style     : 'display: inline',
			 submitdata : {table: table},
			 submit    : '<span>&nbsp;&nbsp;<input type="submit" value="OK"></span>',
			 callback : function(value, settings) {
				$(this).next('.message').show();
				$(this).next('.message').html('');
         		$(this).next('.message').append('Updated');
				$(this).next('.message').fadeOut(2000);
    		 }
     });
	 var sum = 0;
	 var thisNum = 0;

	 $('.meetingGroupMtgCount').each(function() {
		thisNum = parseInt($(this).html());
		if(thisNum == 0) {
        	sum += 1;
			$(this).closest('tr').attr('bgcolor','#FF6666');
		}
    });
	$('#wrapper div.main_content table.tabletext thead.meetingHeader tr.titleRow th h3').append('&nbsp;&nbsp; - &nbsp;&nbsp;('+sum+'&nbsp; with no meetings)');
});
</script>
      <table class="tabletext tablegroups">
      	<thead class="meetingHeader">
          <tr class="titleRow">
            <th colspan="4"><h3>Groups&nbsp;&nbsp;&nbsp;(<?php echo $num_rows ?>)</h3></th>
          </tr>
          <tr class="alternateRow">
            <th>Group</th>
            <th>Intergroup Rep</th>
            <th id="numMtgsHeader"># of Meetings</th>
            <th></th>
          </tr>
        </thead>
          <?php		
$i = 0;
while ($group_row = mysql_fetch_assoc($group_result))
	{
		if ($i%2 == 0) 
		{
		$rowcolor="$reprowcolor";
		} else 
		{
		$rowcolor="white";
		}	
	
		
		
			//report data	?>
          <tr bgcolor="<?php echo $rowcolor?>">
            <td><div class="meetingGroupName"><span class="meetingEdit" id="<?php echo $group_row['id'];?>_groupname"><?php echo $group_row['groupname'];?></span><span class="message"></span></div></td>
            <td><div class="meetingGroupIR"><?php echo $group_row['ir_fname'].'&nbsp;'.$group_row['ir_lname'];?></div></td>
            <td><div class="meetingGroupMtgCount"><?php echo $group_row['counter'];?></div></td>
            <td><div class="meetingDelete">
            		<a href="meetings.php?page=group_edit&id=<?php echo $group_row['id']?>&return_to=meetings.php?page=groups"><img src="../images/edit_button.png"></a>
            		<a href="deleteform.php?id=<?php echo $group_row['id']?>&table=groups&return_to=meetings.php?page=groups"><img src="../images/delete_button.png"></a>
                </div>
            </td>
          </tr>
          <?php 
	$i++;				
	}
echo "</table>";
mysql_close($conn);}?>
        </table>